package cn.kgc.springcloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/2/21
 * @Description:
 */
@RestController
@RequestMapping("hystrix")
public class HystrixController {

    @RequestMapping("m1")
    @HystrixCommand(fallbackMethod="method1FallbackMethod")
    public String method1(Integer id){

        Date date = new Date(System.currentTimeMillis());
        String format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(date);
        System.out.println("date = " + format);


        if(id<0){
            throw  new RuntimeException("参数不合法");
        }
       return "HystrixController ok";
    }

    // method1 的快速响应方法  返回值类型和参数列表要保持和@HystrixCommand标识的方法一致   托底数据
    public String method1FallbackMethod(Integer id){

        return "参数不合法"+id;
    }




}
